package com.l.controller.qita;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;

@SuppressWarnings("serial")
public class SuijiSC extends JFrame implements ActionListener {
	private JButton b1,b2,b3;

	public SuijiSC() {
		this.setTitle("按钮事件测试");
		Container c = this.getContentPane();
		// 使用表格布局1行2列
		c.setLayout(new GridLayout(1, 3));
		b1 = new JButton("A");
		b2 = new JButton("B");
		b3 = new JButton("C");
		/* 为按钮b1,b2添加按钮事件 */
		b1.addActionListener(this);
		c.add(b1);
		b2.addActionListener(this);
		c.add(b2);
		b3.addActionListener(this);
		c.add(b3);
		this.setSize(500, 100);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	/* 按钮事件的响应方法 */
	public void actionPerformed(ActionEvent e) {
		// 通过getSource方法获得当前按钮的对象
		if (e.getSource() == b1) {
			String a = "冷、煦、顼、瑄、妍、嫣、熙、曦、熹、晞、歆、馨、馥、雪、笑、潇、越、悦、瑶、翼、奕、婳、瑾、婧、姁、珂、晗、"
					+ "毓、瑛、雅、赟、蕴、嫱、婵、娉、嫒 、嬟、妙、岚、澜、婉、枫、洁、芬、昭、珊、琀、翚、嫽、琳、霖、翎、昕、璇、绚、霏、清";
			String[] b = a.split("、");
			Random rand = new Random();
			String c = "";
			for (int i = 0; i < 3; i++) {
				int num = rand.nextInt(b.length);
				c = c + b[num];
			}
			System.out.println(c);
		}
		if (e.getSource() == b2) {
			String a = "1、2、3、4、5";
			String[] b = a.split("、");
			Random rand = new Random();
			String c = "";
			for (int i = 0; i < 3; i++) {
				int num = rand.nextInt(b.length);
				c = c + b[num];
			}
			System.out.println(c);
		}
		if (e.getSource() == b3) {
			String a = "a、b、c、d、e";
			String[] b = a.split("、");
			Random rand = new Random();
			String c = "";
			for (int i = 0; i < 3; i++) {
				int num = rand.nextInt(b.length);
				c = c + b[num];
			}
			System.out.println(c);
		}
	}

	public static void main(String[] args) {
		new SuijiSC();
	}
}
